//
//  WXPServiceBtn.m
//  全局的右上角意见反馈
//
//  Created by wxp on 2025/2/25.
//

#import "WXPServiceBtn.h"

@implementation WXPServiceBtn

#pragma mark - lazy
- (UIButton *)btnService{
    if (_btnService == nil) {
        _btnService = [UIButton new];
        [_btnService setImage:[UIImage imageNamed:@"icon-service"] forState:UIControlStateNormal];
        _btnService.tag = 1;
        [_btnService addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btnService;
}
- (WXPGlobalFeedbackView *)feedbackView
{
    if (_feedbackView == nil) {
        _feedbackView = [WXPGlobalFeedbackView  new];
    }
    return  _feedbackView;
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];//背景色
        self.widthHeight = XY(32, 32);
        [self addSubView];//添加子视图
    }
    return self;
}

#pragma mark - 点击事件
- (void)btnClick:(UIButton *)sender{
    switch (sender.tag) {
        case 1:
        {
            [NSObject clickFeedback];
            [sender addClickAnimate];
            if(self.blockServiceClick){
                self.blockServiceClick();
            }else{
                UIWindow * window = [UIApplication sharedApplication].windows.firstObject;
                [window endEditing:true];
                [self.feedbackView requestCustomerServiceInfo];
                [window addSubview:self.feedbackView];
            }
        }
            break;
            
        default:
            break;
    }
}

// 添加subview
- (void)addSubView{
    [self addSubview:self.btnService];
    [self resetViewWithModel:nil];
}

#pragma mark - 刷新view
- (void)resetViewWithModel:(id)model{
    self.btnService.widthHeight = self.widthHeight;
    self.btnService.leftTop = XY(0, 0);
}


@end
